Friday, September 9, 2016

Arduino_KY-015_Temperature_and_humidity_sensor_module

KY-015 37-1 Temperature and humidity sensor module (DHT11)

Hardware

Connections between the Arduino for this temperature and humidity sensor from the 37in1 sensor kit with the KY-015 DHT11 module
  • Arduino pin 8 --> Pin S module
  • Arduino GND --> Pin - module
  • Arduino +5    --> Pin Middle

Program

The temperature and humidity values are displayed on the Serial monitor (To use the Codebender Serial monitor you need to connect it !)

Serial monitor


More info





// ** Arduino KY-015 Temperature and humidity sensor module ** /* ** HARDWARE Arduino pin 8 --> Pin S module Arduino GND --> Pin - module Arduino +5 --> Pin Middle DHT11 Temperature and humidity sensor */ int DHpin = 8; byte dat [5]; byte read_data () { byte data; for (int i = 0; i < 8; i ++) { if (digitalRead (DHpin) == LOW) { while (digitalRead (DHpin) == LOW); // wait for 50us delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1' if (digitalRead (DHpin) == HIGH) data |= (1 << (7 - i)); // high front and low in the post while (digitalRead (DHpin) == HIGH); // data '1 ', wait for the next one receiver } } return data; } void start_test () { digitalWrite (DHpin, LOW); // bus down, send start signal delay (30); // delay greater than 18ms, so DHT11 start signal can be detected digitalWrite (DHpin, HIGH); delayMicroseconds (40); // Wait for DHT11 response pinMode (DHpin, INPUT); while (digitalRead (DHpin) == HIGH); delayMicroseconds (80); // DHT11 response, pulled the bus 80us if (digitalRead (DHpin) == LOW); delayMicroseconds (80); // DHT11 80us after the bus pulled to start sending data for (int i = 0; i < 4; i ++) // receive temperature and humidity data, the parity bit is not considered dat[i] = read_data (); pinMode (DHpin, OUTPUT); digitalWrite (DHpin, HIGH); // send data once after releasing the bus, wait for the host to open the next Start signal } // *** SETUP *** void setup () { Serial.begin (9600); pinMode (DHpin, OUTPUT); } // *** LOOP *** void loop () { start_test (); Serial.print ("Current humdity ="); Serial.print (dat [0], DEC); // display the humidity-bit integer; Serial.print ('.'); Serial.print (dat [1], DEC); // display the humidity decimal places; Serial.println ('%'); Serial.print ("Current temperature ="); Serial.print (dat [2], DEC); // display the temperature of integer bits; Serial.print ('.'); Serial.print (dat [3], DEC); // display the temperature of decimal places; Serial.println ('C'); delay (700); }

Thursday, September 8, 2016

Arduino_BMP180_barometric_pressure

BMP180 barometric pressure sensor tested with Arduino.
This is a sensor for air pressure and temperature. Do not connect +5V to +/VDD  of this sensor!
Sensor will be damaged!

Hardware connections

  • Vin     +3v3
  • GND GND
  • SCL  SCL
  • SDA  SDA

Program on Codebender


Program

// 2016 JanJeronimus copy from

/* BMP180 Absolute Pressure
Mike Grusin, SparkFun Electronics

This sketch shows how to get an absolute pressure reading from the BMP180
barometric pressure sensor. https://www.sparkfun.com/products/11824

Hardware connections:

-/GND to GND
+/VDD to 3.3V

(WARNING: do not connect +/VDD to 5V or the sensor will be damaged!)

You will also need to connect the I2C pins (SCL and SDA) to your
Arduino. The pins are different on different Arduinos:

Any Arduino pins labeled:  SDA  SCL
Uno, Redboard, Pro:        A4   A5
Mega2560, Due:             20   21
Leonardo:                   2    3

Leave the IO (VDDIO) pin unconnected. This pin is for connecting
the BMP180 to systems with lower logic levels such as 1.8V
*/

// Include the needed libraries. The SFE_BMP180 library will need to be
// added to your arduino/libraries folder

#include <SFE_BMP180.h>
#include <Wire.h>

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

void setup()
{
  Serial.begin(9600);
  Serial.println("REBOOT");

  // Initialize the sensor (it is important to get calibration values stored on the device).

  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    // Oops, something went wrong, this is usually a connection problem,
    // see the comments at the top of this sketch for the proper connections.

    Serial.println("BMP180 init fail\n\n");
    while(1); // Pause forever.
  }
  Serial.println("deg C, deg F, abs press mbar, abs press inHg");
}

void loop()
{
  char status;
  double T,P;

  // You must first get a temperature measurement to perform a pressure reading.
  
  // Start a temperature measurement:
  // If request is successful, the number of ms to wait is returned.
  // If request is unsuccessful, 0 is returned.

  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);

    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.

    status = pressure.getTemperature(T);
    if (status != 0)
    {
      // Print out the measurement:
      Serial.print(T,2);
      Serial.print(", ");
      Serial.print((9.0/5.0)*T+32.0,2);
      Serial.print(", ");
      
      // Start a pressure measurement:
      // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
      // If request is successful, the number of ms to wait is returned.
      // If request is unsuccessful, 0 is returned.

      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);

        // Retrieve the completed pressure measurement:
        // Note that the measurement is stored in the variable P.
        // Note also that the function requires the previous temperature measurement (T).
        // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
        // Function returns 1 if successful, 0 if failure.

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          Serial.print(P,2);
          Serial.print(", ");
          Serial.println(P*0.0295333727,2);
        }
        else Serial.println("error retrieving pressure measurement\n");
      }
      else Serial.println("error starting pressure measurement\n");
    }
    else Serial.println("error retrieving temperature measurement\n");
  }
  else Serial.println("error starting temperature measurement\n");

  delay(1000);  // Pause for one second.
}

Output

REBOOT
BMP180 init success
deg C, deg F, abs press mbar, abs press inHg


24.68, 76.42, 1018.39, 30.08

Remark

The barometric pressure sensor is an I2C device found at address 0x77
(You can check this using an I2C scan program https://codebender.cc/sketch:358105

Links

https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup-

Wednesday, September 7, 2016

Arduino_KY-017_Mercury_open_optical_module

Arduino KY-017 Mercury open optical module

Mercury tilt switch that allows you to detect the tilt of your object.
Module also contains a status led.
One bad thing about this module is the toxic mercury.
As long as the glass bulb is closed it will give no problems.
This module needs to be disposed as toxic waste !

Hardware

  • S           Arduino Pin 3
  • middle   +5V
  • -           GND

Function

Arduino led (Pin 13) displays tilt status.

More info

Program

// ** Arduino KY-017 Mercury open optical module ** /* ** HARDWARE ** S Pin 3 middle +5V - GNF int buttonpin = 3; // define the mercury tilt switch sensor interface int Led = 13 ; // define LED Interface int val ; // define numeric variables val // *** SETUP *** void setup () { pinMode (Led, OUTPUT) ; // define LED as output interface pinMode (buttonpin, INPUT) ; // define the mercury tilt switch sensor output interface } // *** LOOP *** void loop () { val = digitalRead (buttonpin) ; // read the values assigned to the digital interface 3 val if (val == HIGH) // When the mercury tilt switch sensor detects a signal, LED flashes { digitalWrite (Led, HIGH); } else { digitalWrite (Led, LOW); } }

Tuesday, September 6, 2016

Arduino_MQ2_gas_sensor

The MQ2 gas sensor is sensible to Methane, Butane, LPG and Smoke and is the first sensor from the Arduino Gas sensor kit for Arduino that i tested.

The script below (also avalable as codebender to run immediate) is used to read the analog value (A0) and the digital signal (connected to D12)


/* 2016 MQ-2 GAS Sensor  JanJeronimus
Gets digital and analog value from gas sensor every second
Writes time [ uptime millis() ]  , 
 digital gas sensor and
 analog gas sensor value to the serial port
*/

const int gasPinA = A0 ; //GAS sensor Analog output pin to Arduino analog A0 pin
const int gasPinD = 12; //GAS sensor Digital output pin to Arduino

int val = 0;     // variable to store the Digital read value

void setup()
{
pinMode(gasPinD, INPUT);
Serial.begin(9600); //Initialize serial port - 9600 bps
}

void loop()
{
Serial.print( "Time " ) ;
Serial.print( millis() ) ;
Serial.print( " , Digital " ) ;
Serial.print( val ) ;
Serial.print( " , Analog " ) ;
Serial.println( analogRead(gasPinA) );
delay(1000); // Print value every 1 sec.
}
To get a reliable signal a burn-in time is needed.
When using the sensor for the first time (without burn-in time) the analog signal indicates a value of 130 and in a few minutes dropping to 80 and slowly dropping more.
If opening gas from a cigarette lighter near the sensor the signal rises to +/- 340. This indicates that the sensor is working. After a few hours the analog signal has dropped to 27. If spraying some aftershave on my hand and immediate putting my hand near the sensor the signal also rises to this value. In this case it takes more time before the signals drops down again.

Monday, September 5, 2016

Arduino_Gas_Sensor_set

Received a set of 9 gas sensor for Arduino from Aliexpress ( China ).
You can find a table with some details of the gas sensors in this post.
MQ-8 MQ-9 MQ-135





MQ-4 MQ-5 MQ-6


MQ-2 MQ-3 MQ-4

The  PCBs for the sensors all look the same with pins
  • A0 Analog signal
  • D0 Digital signal (treshhold controlled by pot meter)
  • GND Ground
  • VCC Power (+5V)
The PCB has a pot meter and two leds
  • Power led
  • D0 level led
The D0 level led turns on if the analog signal comes above the threshold regulated by the pot meter. 
< ThresholdLed OffD0 pin signal  1
>ThresholdLed OnD0 pin signal 0

Quick scanning the info also learned me that the MQ-7 needs alternating 60 seconds 5v, 90 seconds 1.4 volt ( http://forum.arduino.cc/index.php?topic=239693.0 ) . The hardware for all the sensors looks the same but it seem there are some differences! 
Also storage conditions (when not in use) of these sensors seem to be important.
When starting this project i expected that i could test some of these sensors and publish this the same day on my blog. After collecting some info i decided to make this a general info start article and publish the test in separated articles.

Burn-in time

Reading more information i found that also  burn-in time is needed for this sensors Some datasheets use the term "preheat", but it is the time to burn-in the sensor. This is meant to make the sensor readings more consistent. 
A time of 12 or 24 hours is usually used for the burn-in time.The Burn-in is achieved by applying normal power to the sensor (to the heater and with the 'A' and 'B' pins connected, and with a load-resistor). In some special cases a specific burn-in is needed. See the datasheet if the sensor needs such a specific burn-in.
After the "burn-in time", the heater needs to be on for about 3 minutes before the readings become stable.
The sensors that use 5V or 6V for the internal heater do get warm. They can easily get 50 or 60 degrees Celsius. If it is used in a battery operated device, a transistor or logic-level mosfet could also be used to switch the heater on and off. I also want to "burn-in" with a power supply and not with batteries
After creating the circuit it could take more than 24 hours to get the first consistent measurements. 
As details can be found in the datasheets of the sensors (Links included in the table in this article).

Test gas

To test the sensors some gasses would be needed. Some ideas to test:
Ethanol (Alcohol) 
Butane (Weed burner gas)
Gas from a cigarette lighter
Smoke ( from a fire )
Perfume / Aftershave
Ammonia
Car exhaust
Car fuel
Hydrogen (created by electrolysis or metal with strong acid)

My gas sensors:

SensorGasDatasheetTested
MQ2Methane, Butane, LPG, Smoke Datasheet
Y
MQ3Alcohol, Ethanol, SmokeDatasheet
n
MQ4Methane, CNG GasDatasheet
n
MQ5Liquified gas, Coal gasDatasheet
n
MQ6LPG, Isobutane, PropaneDatasheet
n
MQ7Sensitive Detector CO gas
(Needs alternating 60 seconds 5v, 90 seconds 1.4 volt)
http://forum.arduino.cc/index.php?topic=239693.0

Datasheet
n
MQ8HydrogenDatasheet
n
MQ9CO, Flammable gassesDatasheet
n
MQ135Air quality / Hazardous gas
(Benzene, Alcohol, smoke, NH3)
Datasheet
n

Item in the first column "Sensor" will links to the "blog label" of the sensor to find all articles in this blog labeled with this sensor
"Datasheet" will link to a datasheet of the sensor.
"Tested" will updated with a link to the blog article with the test.
I hope to publish in the next blog article a small test of the MQ2 sensor!

Links


Friday, September 2, 2016

VoiceRecordModule_1820

Tested a voice record and playback module 1820 that i want to use in a domotica project.
I provided power to the module with an Arduino.
  • Red REC button needs to be pressed to record a message ( 10 seconds max)
  • Black PLAYE button plays the recorded message (complete)
  • Black PLAYL button plays the recorded message until released.

On the module are also REC, PLAYE and PLAYL pins to use a micro-controller ( e.g. Arduino. or ESP8266  )

Both 5V and 3V3  (to use in a ESP8266 project) give reasonable voice quality however the volume is quite low.

Changing from 5V to 3V3 gives no significant difference in playback volume.
After switching the power on and off the module still can playback the recorded message.
When recording it is best to speak close to the microphone (on the PCB board.)
Especially for playback outdoor or with background noise more volume would be needed.
I had planned to make Wifi controlled voice recorder with ESP8266. However due to the low output volume i decided to not (yet) permanent create this project. Perhaps i need to add a (cheap) amplifier.














Thursday, September 1, 2016

Homewizard elektrisch rolgordijn.

kwam precies na 3 dagen. De dag voor de bezorging een mail ontvangen dat pakket was overgedragen aan transporteur en de volgende dag tussen 8 en 10 een mail zou komen met bezorgtijdstip. Een mail van 8:38 ontvangen dat pakket tussen 13:04 en 15:04 bezorgd zou worden. Om 14:04 stopte een grote vrachtauto voor de deur en een paar minuten later kon het pakket met daarin het rolgordijn in ontvangst genomen worden. Een lange houten lat was langs de doos geplakt om het rolgordijn te beschermen. Het rolgordijn zat in de doos in plastic verpakt met ophangbeugeltjes, netvoeding, handleidingen en een doosje met afstandsbediening en een ophangbeugeltje voor de afstandsbediening met bijbehorende schroefjes. Het enige wat nog ontbrak waren schroeven voor het ophangen van het rolgordijn zelf. (Er moet natuurlijk wat te klagen over blijven.)
Het ophangen zelf ging iets lastiger dan verwacht. Nadat het oude rolgordijn weggehaald was gaatjes voorgeboord en ophangbeugeltjes volgens de handleiding geplaatst. Soms toch nog lastig te schroeven (vooral als er ook een boortje breekt en in het gaatje blijft zitten.) Bovendien merkte ik dat het kozijn (vooral) op de plaatsen waar ik de beugeltjes wilde schroeven niet helemaal vlak was. De maat van het rolgordijn wist ik maar van te voren weet je natuurlijk niet waar de gaatjes in de beugeltjes zitten. Een ringetje zou niet niet voldoende helpen, uiteindelijk een paar moertjes als afstandhouders misbruikt om voldoende ruimte te hebben dat het rolgordijn in de beugeltjes kon klikken.
Geprobeerd in mijn eentje het gordijn in de beugeltjes te klikken. Dat lukte dus helemaal niet.
Volgens de handleiding moet het rolgordijn tegen de onderkant van de bevestigingsclips gedrukt worden zodat deze in het profile valt. Daarna bovenkant omhoog duwen tot deze vastklikt. De achterkant waar de beugeltjes in moeten klikken goed bekeken met een los beugeltje. Het blijkt dat dis dus helemaal niet gaat. Wel kan het beugeltje omgedraaid worden en dan kan je het er wel in klikken. Dus beugeltjes op de muur omgedraaid en dan zitten ze net te hoog tegen het plafond waardoor het rolgordijn kantelen om er in te hangen niet lukt. Dus beugeltjes uiteindelijk iets lager geplaatst en dan gaat het wel.
Voor gebruik moet motor eerst opgeladen worden. De adapter blijkt rood licht te geven als teken dat de accu nog niet voldoende opgeladen is. Volgens handleiding opladen tot groen. Na tijdje geen rood meer maar blauw licht. (Groen heb ik nog niet gezien.)
Dan de afstandbediening koppelen met het rolgordijn. Achterop zit gaatje met knopje P2. Bij het koppelen van de afstandbediening met het rolgordijn een kleine schroevendraaier gebruikt om het in te drukken. Koppelen ging goed en ook het daarna instellen van hoogste en laagste stand. Ook nog een voorkeur stand volgens de handleiding toegevoegd.
Daarna afstandsbediening koppelen met de Homewizard. Was even puzzelen om te ontdekken dat op de Homewizard het rolgordijn als “Zonweringen & gordijnen” - “Brel” moest worden aangemeld. Hierbij een een pen gebruikt om P2 achter op de afstandsbediening in te drukken. Echter het knopje blijkbaar wat scheef ingedrukt waardoor het onder het gaatje schoof en P2 altijd ingedrukt bleef! Dit was niet dus de bedoeling. Batterij verwijderd en knopje weer voorzichtig terug geschoven....
Uiteindelijk functioneert dit mooie (maar helaas prijzige) systeem naar tevredenheid !

Links

Homewizard shop elektrisch rolgordijn

Wednesday, August 31, 2016

Arduino_Shield_TFT_LCD_2_Touch

Recently i received via another (different) TFT 2.4 shield:












Tried SDcard read and wri
te program and SDcard seems to work!
The info program i found to read info from this second TFT LCD shields gave this info:
reg(0x0000) 00 00 ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 00 00 00 Manufacturer ID
reg(0x0009) 00 00 61 00 00 Status Register
reg(0x0061) 00 00 RDID1 HX8347-G
reg(0x0062) 00 00 RDID2 HX8347-G
reg(0x0063) 00 00 RDID3 HX8347-G
reg(0x0064) 00 00 RDID1 HX8347-A
reg(0x0065) 00 00 RDID2 HX8347-A
reg(0x0066) 00 00 RDID3 HX8347-A
reg(0x0067) 00 00 RDID Himax HX8347-A
reg(0x00B0) 00 00 RGB Interface Signal Control
reg(0x00B4) 00 00 Inversion Control
reg(0x00B6) 00 00 00 00 00 Display Control
reg(0x00B7) 00 00 Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00 ILI9481, HX8357-B
reg(0x00C0) 00 00 00 00 00 00 Panel Control
reg(0x00CC) 00 00 Panel Control
reg(0x00D0) 00 00 00 Power Control
reg(0x00D2) 00 00 00 00 00 NVM Read
reg(0x00D3) 00 00 00 00 ILI9341, ILI9488
reg(0x00DA) 00 00 RDID1
reg(0x00DB) 00 00 RDID2
reg(0x00DC) 00 00 RDID3

reg(0x00EF) 00 00 00 00 00 00 ILI9327

The LCD Demo Statistics program did not work with this TFT shield!

As i did not yet tested the touch possibilities with my first shield, i wanted to test it with both shields.Found a "paint program" TFT Colorbar for the TFT shield.
This program TFT Colorbar program displays colored blocks and a drawing area on the screen. It reacted to touching the screen but not in a correct way. X and Y seemed swapped.
Found on line 35 
landscape=0 and changed this to landscape=1 After this the program worked (on both TCT screens) !

TFT Colorbar

"paint program" (with line 35  Landscape changed from 0 to 1)
On codebender:

Code:// the regular Adafruit "TouchScreen.h" library only works on AVRs

// different mcufriend shields have Touchscreen on different pins
// and rotation.
// Run the UTouch_calibr_kbv sketch for calibration of your shield

//#include <Adafruit_GFX.h>    // Core graphics library
//#include <Adafruit_TFTLCD.h> // Hardware-specific library
//Adafruit_TFTLCD tft(A3, A2, A1, A0, A4);
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;       // hard-wired for UNO shields anyway.
#include <TouchScreen.h>

#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif


// These are the pins for some typical shields!
// S6D0154: YP=A1, XM=A2, YM=7, XP=6
// ST7783 : YP=A2, XM=A1, YM=6, XP=7
// ILI9320: YP=A2, XM=A3, YM=8, XP=9
// ILI9325: YP=A1, XM=A2, YM=7, XP=6
// ILI9325BG: YP=A2, XM=A1, YM=6, XP=7
// ILI9341: YP=A2, XM=A1, YM=7, XP=6
// ILI9488: YP=A1, XM=A2, YM=7, XP=6
// R65109V: YP=A2, XM=A1, YM=6, XP=7

// most mcufriend shields use these pins and Portrait mode:
uint8_t YP = A1;  // must be an analog pin, use "An" notation!
uint8_t XM = A2;  // must be an analog pin, use "An" notation!
uint8_t YM = 7;   // can be a digital pin
uint8_t XP = 6;   // can be a digital pin
uint8_t Landscape = 1;

uint16_t TS_LEFT = 920;
uint16_t TS_RT = 150;
uint16_t TS_TOP = 940;
uint16_t TS_BOT = 120;

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
//  ( was 300 )
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 250);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

int16_t BOXSIZE;
int16_t PENRADIUS = 3;
uint16_t oldcolor, currentcolor;

void setup(void)
{
    Serial.begin(9600);
    Serial.println(F("Paint_kbv !"));

    tft.reset();
    uint16_t identifier = tft.readID();
//    if (identifier == 0) identifier = 0x9341;
/*    if (0) {
    } else if (identifier == 0x0154) {
        Serial.println(F("Found S6D0154 LCD driver"));
        TS_LEFT = 914; TS_RT = 181; TS_TOP = 957; TS_BOT = 208;
    } else if (identifier == 0x7783) {
        Serial.println(F("Found ST7783 LCD driver"));
        TS_LEFT = 865; TS_RT = 155; TS_TOP = 942; TS_BOT = 153;
        Landscape = 1;
    } else if (identifier == 0x9320) {
        Serial.println(F("Found ILI9320 LCD driver"));
        YP = A3; XM = A2; YM = 9; XP = 8;
        TS_LEFT = 902; TS_RT = 137; TS_TOP = 941; TS_BOT = 134;
    } else if (identifier == 0x9325) {
        Serial.println(F("Found ILI9325 LCD driver"));
        TS_LEFT = 900; TS_RT = 103; TS_TOP = 96; TS_BOT = 904;
    } else if (identifier == 0x9341) {
        Serial.println(F("Found ILI9341 LCD driver BLUE"));
        TS_LEFT = 920; TS_RT = 139; TS_TOP = 944; TS_BOT = 150;
        Landscape = 0;
    } else if (identifier == 0) {
        Serial.println(F("Found ILI9341 LCD driver DealExtreme"));
        TS_LEFT = 893; TS_RT = 145; TS_TOP = 930; TS_BOT = 135;
        Landscape = 1;
    } else if (identifier == 0 || identifier == 0x9341) {
        Serial.println(F("Found ILI9341 LCD driver RED"));
        TS_LEFT = 128; TS_RT = 911; TS_TOP = 105; TS_BOT = 908;
        Landscape = 1;
    } else if (identifier == 0x9488) {
        Serial.println(F("Found ILI9488 LCD driver"));
        TS_LEFT = 904; TS_RT = 170; TS_TOP = 950; TS_BOT = 158;
    } else if (identifier == 0xB509) {
        Serial.println(F("Found R61509V LCD driver"));
        TS_LEFT = 889; TS_RT = 149; TS_TOP = 106; TS_BOT = 975;
        Landscape = 1;
    } else {
        Serial.print(F("Unknown LCD driver chip: "));
        Serial.println(identifier, HEX);
        return;
    } */ 
    ts = TouchScreen(XP, YP, XM, YM, 250);     // was 300 call the constructor AGAIN with new values.
    tft.begin(identifier);
    BOXSIZE = tft.width() / 6;
    tft.fillScreen(BLACK);

    tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
    tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
    tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, GREEN);
    tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, CYAN);
    tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, BLUE);
    tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, MAGENTA);

    tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
    currentcolor = RED;
    delay(1000);
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop()
{
    int tmp;
    TSPoint p = ts.getPoint();

    // if sharing pins, you'll need to fix the directions of the touchscreen pins
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    // we have some minimum pressure we consider 'valid'
    // pressure of 0 means no pressing!

    if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
        if (Landscape) {   // swap X and Y
            tmp = p.x;
            p.x = p.y;
            p.y = tmp;
        }
        // scale from 0->1023 to tft.width  i.e. left = 0, rt = width
        // most mcufriend have touch (with icons) that extends below the TFT 
        // screens without icons need to reserve a space for "erase"
        p.x = map(p.x, TS_LEFT, TS_RT, 0, tft.width());
        p.y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());

        if (p.y < BOXSIZE) {
            oldcolor = currentcolor;

            if  (p.x < BOXSIZE)   {                currentcolor = RED;                tft.drawRect(          0, 0, BOXSIZE, BOXSIZE, WHITE);} 
            else if (p.x < BOXSIZE * 2) {                currentcolor = YELLOW;             tft.drawRect(BOXSIZE,     0, BOXSIZE, BOXSIZE, WHITE);} 
            else if (p.x < BOXSIZE * 3) {                currentcolor = GREEN;              tft.drawRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, WHITE);} 
            else if (p.x < BOXSIZE * 4) {                currentcolor = CYAN;               tft.drawRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, WHITE);} 
            else if (p.x < BOXSIZE * 5) {                currentcolor = BLUE;               tft.drawRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, WHITE);} 
            else if (p.x < BOXSIZE * 6) {                currentcolor = MAGENTA;            tft.drawRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, WHITE);}

            if (oldcolor != currentcolor) {
                if (oldcolor == RED) tft.fillRect  (0, 0, BOXSIZE, BOXSIZE, RED);
                if (oldcolor == YELLOW) tft.fillRect(BOXSIZE    , 0, BOXSIZE, BOXSIZE, YELLOW);
                if (oldcolor == GREEN) tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, GREEN);
                if (oldcolor == CYAN) tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, CYAN);
                if (oldcolor == BLUE) tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, BLUE);
                if (oldcolor == MAGENTA)tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, MAGENTA);
            }
        }
        if (((p.y - PENRADIUS) > BOXSIZE) && ((p.y + PENRADIUS) < tft.height())) {
            tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
        }
        if (p.y > tft.height() - 10) {
            Serial.println("erase");
            // press the bottom of the screen to erase
            tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - BOXSIZE, BLACK);
        }
    }
}

On the shield at the top of the TFT screen is a button that reacts the same as the Arduino reset button. 
Detail of this TFT screen (2)  are the 5 icons on the bottom om the TFT screen :
[Home]  [Book]  [Mail]  [Photo]  [Video]

Link to some interesting info:

Tuesday, August 30, 2016

Arduino_KY-018_Photo_resistor_module

Arduino KY-018 Photo resistor module

Photo resistor 37in1 sensor KY-018 tested with Arduino

Hardware connections

  • Module Signal (S)  -  Arduino A5  (analog in) 
  • Module +5V (Pin2) -  Arduino 5V 
  • Module GND          - Arduino GND

Program

The program below reads the analog signal and outputs it to the serial monitor..
Open serial monitor to see the values.

Console



Links

https://tkkrlab.nl/wiki/Arduino_KY-018_Photo_resistor_module