This example will demonstrate the use of an Arduino UNO in monitoring a digital pin when an object is placed in front of the detector.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the D2 pin is assigned followed by a variable to store the values read. This allows easier use later in your program. A setup informs the system that the pins are inputs and then launches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyestudio obstacle detection Module - BDAA100029. The program monitors connected digital pin and outputs the value to the serial monitor. modified 19th December 2019 by Sebastian Karam - Flux Workshop */ int digitalpin = 2; // define digital OUT signal pin int digital; // define variable to store value read from pin void setup() { pinMode(digitalpin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { digital = digitalRead(digitalpin); // read the voltage level on the D2 Serial.println((String)"Detection Level: " + digital ); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. Taking my hand and placing it front of the detector and emitter. You can then see a grounding in the output.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin voltage level as a current is applied to the terminals over the range that the sensor responds to.
Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a variable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then launches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. As the analog pins interpret values over a 1024 part range, we do some simple scaling for our amp range of -5 to 5A. Following that we send the value to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes ACS712 5A sensor module - BDAA100028 The program monitors a connected analog pin, interprets a voltage level and outputs the value to the serial monitor. modified 5th December 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Current: " + (((analogA-512)*10)/1024) + "A"); // send the result to the serial monitor delay(500); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in line with a 2A device. When powered, the sensor picks it out at 2A. The polarity is then switched and it goes to -2A.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin voltage level as a current is applied to the terminals over the range that the sensor responds to.
Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a variable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then launches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. As the analog pins interpret values over a 1024 part range, we do some simple scaling for our amp range of -5 to 5A. Following that we send the value to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyestudio ACS712 5A sensor module - BDAA100027 The program monitors a connected analog pin, interprets a voltage level and outputs the value to the serial monitor. modified 5th December 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Current: " + (((analogA-512)*10)/1024) + "A"); // send the result to the serial monitor delay(500); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in line with a 2A device. When powered, the sensor picks it out at 2A. The polarity is then switched and it goes to -2A.
This example will demonstrate the use of an Arduino UNO reading data from the sensor. Once connected and the program loaded, it will read the temperature and humidity, every second. This will use the SHT1x library library created by Jonathan Oxer and Maurice Ribble.
Wire the two boards together as can be seen in the image below, taking care to match the pin numbers.
The code consists of an include, definitions, initilisation, setup and loop. First the SHT1x library is linked to the code. This is followed by the initilisation of the sensor object used by the library and the pins it is connected to. The setup initilises the serial connection. The loop requests the temperature and humidity from the library, storing it in the variables declared. The values are then output to the serial connection, pausing for a moment and repeating.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the SimpleDHT library and Keyes SHT10 Temperature and Humiditiy Module - BDAA100025 The program uses the SHT1x library to interface with the module and return a temperature and humidity to the serial monitor. Then repeat the request. modified 28 November 2019 by Sebastian Karam - Flux Workshop The SHT1x library created by Jonathan Oxer and Maurice Ribble https://github.com/practicalarduino/SHT1x */ #include// include the SHT1x library // Specify data and clock connections and instantiate SHT1x object #define dataPin 10 // define the data pin the sensor is connected to #define clockPin 11 // define the clock pin the sensor is connected to SHT1x sht1x(dataPin, clockPin); // create the sensor object void setup() { Serial.begin(9600); // initialise the serial connection Serial.println("Flux Workshop Example"); } void loop() { float temperature; // define a variable to store the temperature float humidity; // define a variable to store the humidity // Read values from the sensor temperature = sht1x.readTemperatureC(); // read the values from the SHT10 humidity = sht1x.readHumidity(); // read the values from the SHT10 // Print the values to the serial port Serial.print("Temperature: "); Serial.print(temperature, DEC); // send the result to the serial monitor Serial.print("C / "); Serial.print("Humidity: "); Serial.print(humidity); // send the result to the serial monitor Serial.println("%"); delay(1000); }
With the board loaded with the program and all the connections made, start the serial monitor. An initial value for the temperature and humidity will appear. The output should be as seen below (in this instance, held free, then moist air blown momentarily across it).
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over changing light levels that the sensor responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes ML8511 ultraviolet sensor module - BDAA100024 The program monitors a connected analog pin and outputs the value to the serial monitor. modified 20th November 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"UV level: " + analogA); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in daylight before it is covered. Note the values are low even when detecting, thanks to the lovely British weather we had no sun for the test. When in full sun/under a UV lamp the results should read around 240.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin state as the current sensor monitors an AC live wire.
Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers and names.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a variable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then launches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes Current Sensor Module - BDAA100023. The program monitors a connected analog pin and outputs the value to the serial monitor. modified 6th November 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Current level: " + analogA); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this instance, the live wire of a kettle is passed through the sensor, then I began turning it on and off. You will notice outputs reaches its maximum when it is turned on.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin state as the sensor plate is manipulated.
Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers and names.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a variable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then launches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes Piezo Vibration Sensor Module - BDAA100022. The program monitors a connected analog pin and outputs the value to the serial monitor. modified 6th November 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Vibration level: " + analogA); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this instance, the sensor was held still then tapped wildly for a few moments. You will notice that the output jumpes madly when the sensor is triggered.
This example will demonstrate the use of an Arduino UNO in monitoring a digital pin over the range of light levels that an IR detector responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the D0 pins is assigned followed by a varaiable to store the values read. This allows easier use later in your program. A setup informs the system that the pins are inputs and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyestudio IR Detector Module - BDAA100020. The program monitors connected digital pin and outputs the value to the serial monitor. modified 31st October 2019 by Sebastian Karam - Flux Workshop */ int digitalpin = 2; // define digital OUT signal pin int digital; // define variable to store value read from pin void setup() { pinMode(digitalpin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { digital = digitalRead(digitalpin); // read the voltage level on the D2 Serial.println((String)"IR Light level: Digital " + digital ); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. Taking a common TV remote, the emitter is held up to the detector and a button pressed. You can then see a spike in the output.
The example will demonstrate the use of an Arduino UNO in requesting and interpreting data from a DS18b20 sensor. Once connected and the program loaded, the serial monitor will display a live temperature readout. This will use the OneWire library created by Paul Stoffregen and the DallasTemperature library created by Miles Burton.
Wire the components together as can be seen in the image below, taking care to match the pin numbers.
The code consists of the an include, definition, launch, setup and loop. First the OneWire library and the DallasTemperature library are linked to the code. The sensor pin is defined followed by the OneWire library and DallasTemperature library instances established. The setup launches the serial connection and sensor connection. The loop contains the control program that will run continuously after the setup. It begins by requesting the information from the sensor instance. It then prints the value to the serial monitor.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the DallasTemperature library and DS18b20 Temperature probe - BDAA100019 The program uses the OneWire and DallasTemperature libraries to request and output temperatures from a DS18b20 sensor to the serial monitor. modified 24 October 2019 by Sebastian Karam - Flux Workshop The OneWire library created by Paul Stoffregen https://github.com/PaulStoffregen/OneWire The DallasTemperature library created by Miles Burton https://github.com/milesburton/Arduino-Temperature-Control-Library */ #include#include // Define the pin that the sensor pin #define ONE_WIRE_BUS 2 // Establish a oneWire instance OneWire oneWire(ONE_WIRE_BUS); // Establish Dallas Temperature instance DallasTemperature sensors(&oneWire); void setup(void) { Serial.begin(9600); // Open a serial communication line sensors.begin(); // Start up the DallasTemperature library } void loop(void){ sensors.requestTemperatures(); // Request temperatures from the sensors instance Serial.print("Temperature (Celsius): "); // Print to the serial monitor Serial.print(sensors.getTempCByIndex(0)); // Print the temperature from the library to serial monitor Serial.print("\n"); // Print to the serial monitor delay(1000); // Pause before restarting the loop }
With the board is loaded with the program and all the connections made the module will begin to output a temperature in celcius. The animation below shows a brief loop of the sensor being placed beside a cold cup of water then above a a hot cup of water and then back to the cold.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of light levels that an TEMT6000 sensor responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a variable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then launches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyestudio Ambient Light Sensor Module - BDAA100018. The program monitors a connected analog pin and outputs the value to the serial monitor. modified 16th October 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Ambient Light level: " + analogA); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is facing a bright window before it is covered by a my hand. I then repeat this time just waving across the sensor. You can see the gentler change.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of temperatures.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. The variable is then sent through a small calculation to convert a voltage to temperature in celcius. The calculated value then overwrites the original value held in the variable. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyestudio LM35 temperature sensor module. - BDAA100017 The program monitors an analog pins and outputs the value to the serial monitor. modified 9th October 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OTA/S signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OTA/S signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 analogA = (analogA * 500) / 1024; // convert the voltage level to a temperature Serial.println((String)"Temperature: " + analogA + " degC"); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is on the table and a cup full of boiling water is placed on top of it. It would keep going up if I kept recording, but I am sure you have better things to do with your day.
This example will demonstrate the use of an Arduino UNO in monitoring both an analog and digital pin over a range of vibration levels.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 and D0 pins is assigned followed by a varaiable each to store the values read. This allows easier use later in your program. A setup informs the system that the pins are inputs and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variables declared earlier. Following that we send it to the serial monitor so that the values can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes Vibration Sensor Module - BDAA100015 The program monitors connected analog and digital pin and outputs the value to the serial monitor. modified 26th September 2019 by Sebastian Karam - Flux Workshop */ int analogpin = 0; // define analog OUT signal pin int analog; // define variable to store value read from pin int digitalpin = 2; // define digital OUT signal pin int digital; // define variable to store value read from pin void setup() { pinMode(analogpin, INPUT); // set the OUT signal pin as an input pinMode(digitalpin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analog = analogRead(analogpin); // read the voltage level on the A0 digital = digitalRead(digitalpin); // read the voltage level on the D2 Serial.println((String)"Light level: Analog " + analog + " Digital " + digital ); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor initially still and then, well, we shake like a polaroid picture. You can then see spikes in the output up.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of light levels that an IR detector responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the D0 pins is assigned followed by a varaiable to store the values read. This allows easier use later in your program. A setup informs the system that the pins are inputs and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes IR Detector Module - BDAA100014. The program monitors connected digital pin and outputs the value to the serial monitor. modified 22nd September 2019 by Sebastian Karam - Flux Workshop */ int digitalpin = 2; // define digital OUT signal pin int digital; // define variable to store value read from pin void setup() { pinMode(digitalpin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { digital = digitalRead(digitalpin); // read the voltage level on the D2 Serial.println((String)"IR Light level: Digital " + digital ); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. Taking a common TV remote, the emitter is held up to the detector and a button pressed. You can then see a spike in the output.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of light levels that an IR detector responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 and D0 pins is assigned followed by a varaiable each to store the values read. This allows easier use later in your program. A setup informs the system that the pins are inputs and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variables declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes IR Detector Module - BDAA100013. The program monitors connected analog and digital pin and outputs the value to the serial monitor. modified 19th September 2019 by Sebastian Karam - Flux Workshop */ int analogpin = 0; // define analog OUT signal pin int analog; // define variable to store value read from pin int digitalpin = 2; // define digital OUT signal pin int digital; // define variable to store value read from pin void setup() { pinMode(analogpin, INPUT); // set the OUT signal pin as an input pinMode(digitalpin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analog = analogRead(analogpin); // read the voltage level on the A0 digital = digitalRead(digitalpin); // read the voltage level on the D2 Serial.println((String)"Light level: Analog " + analog + " Digital " + digital ); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in a moderately lit room, resulting in a background value on the analog output. Taking a common TV remote, the emitter is held up to the detector and a button pressed. You can then see a spike in the output.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of light levels that an IR detector responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the D0 pins is assigned followed by a varaiable to store the values read. This allows easier use later in your program. A setup informs the system that the pins are inputs and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes IR Detector Module - BDAA100012. The program monitors connected digital pin and outputs the value to the serial monitor. modified 12th September 2019 by Sebastian Karam - Flux Workshop */ int digitalpin = 2; // define digital OUT signal pin int digital; // define variable to store value read from pin void setup() { pinMode(digitalpin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { digital = digitalRead(digitalpin); // read the voltage level on the D2 Serial.println((String)"IR Light level: Digital " + digital ); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. Taking a common TV remote, the emitter is held up to the detector and a button pressed. You can then see a spike in the output.
This example will demonstrate the use of an Arduino UNO in monitoring an analog and digital pin over the range of light levels that an IR detector responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 and D0 pins is assigned followed by a varaiable each to store the values read. This allows easier use later in your program. A setup informs the system that the pins are inputs and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variables declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes IR Detector Module - BDAA100011. The program monitors connected analog and digital pin and outputs the value to the serial monitor. modified 30th August 2019 by Sebastian Karam - Flux Workshop */ int analogpin = 0; // define analog OUT signal pin int analog; // define variable to store value read from pin int digitalpin = 2; // define digital OUT signal pin int digital; // define variable to store value read from pin void setup() { pinMode(analogpin, INPUT); // set the OUT signal pin as an input pinMode(digitalpin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analog = analogRead(analogpin); // read the voltage level on the A0 digital = digitalRead(digitalpin); // read the voltage level on the D2 Serial.println((String)"Light level: Analog " + analog + " Digital " + digital ); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in a moderately lit room, resulting in a background value on the analog output. Taking a common TV remote, the emitter is held up to the detector and a button pressed. You can then see a spike in the output.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of light levels that an LDR responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes LDR Sensor Module - BDAA100008. The program monitors a connected analog pin and outputs the value to the serial monitor. modified 29th August 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Light level: " + analogA); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in bright sunlight before it is covered by a cup. I then repeat a few more times, as the number change is satisfying.
This example will demonstrate the use of an Arduino UNO in monitoring a digital pin state as the module is shaken.
Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the D2 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send the value to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate us of a captive spring vibration sensor module. BDAA100007 The program monitors the connected digital pin and outputs the value to the serial monitor. modified 16th August 2019 by Sebastian Karam - Flux Workshop */ int digitalpin = 2; // define signal pin int vibration; // define variable to store value read from pin void setup() { pinMode(digitalpin, INPUT); // set the signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { vibration = digitalRead(digitalpin); // read the level on D2 Serial.println((String)"State: " + vibration); // send the result to the serial monitor }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this instance, the sensor was held still then shaken wildly for a few moments. You will notice that the output goes low when the sensor is triggered.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin voltage level as a current is applied to the terminals over the range that the sensor responds to.
Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. As the analog pins interpret values over a 1024 part range, we do some simple scaling for our amp range of -30 to 30A. Following that we send the value to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the ACS712 30A sensor module - BDAA100006 The program monitors a connected analog pin, interprets a voltage level and outputs the value to the serial monitor. modified 14th August 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Current: " + (((analogA-512)*60)/1024) + "A"); // send the result to the serial monitor delay(500); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in line with a 8A device. When powered, the sensor picks it out at 8A. The polarity is then switched and it goes to -8A.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin voltage level as a current is applied to the terminals over the range that the sensor responds to.
Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. As the analog pins interpret values over a 1024 part range, we do some simple scaling for our amp range of -20 to 20A. Following that we send the value to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the ACS712 20A sensor module - BDAA100005 The program monitors a connected analog pin, interprets a voltage level and outputs the value to the serial monitor. modified 2nd August 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Current: " + (((analogA-512)*40)/1024) + "A"); // send the result to the serial monitor delay(500); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in line with a 8A device. When powered, the sensor picks it out at 8A. The polarity is then switched and it goes to -8A.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin voltage level as a current is applied to the terminals over the range that the sensor responds to.
Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a variable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then launches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. As the analog pins interpret values over a 1024 part range, we do some simple scaling for our amp range of -5 to 5A. Following that we send the value to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the ACS712 5A sensor module - BDAA100004 The program monitors a connected analog pin, interprets a voltage level and outputs the value to the serial monitor. modified 26th July 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Current: " + (((analogA-512)*10)/1024) + "A"); // send the result to the serial monitor delay(500); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in line with a 2A device. When powered, the sensor picks it out at -2A. The polarity is then switched and it goes to 2A.
This example will demonstrate the use of an Arduino UNO in monitoring digital pins that output readings from 3 IR detectors. Each responding as it moves from a white reflective surface to a black absorbent one.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the 3 digital pins is assigned followed by individual variables to store the value read. This allows easier use later in your program. A setup informs the system that the pins are inputs and then launches the serial connection. Next we enter the loop, where the values on the pins are read and stored in the variables declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen. As a final addition, a series of 'if' statements read the output (which is combined into a single string above). These then output a relevant message to reflect a robots reaction to the line position.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the a 3 line following module. The program monitors connected digital pins and outputs the value to the serial monitor. The output is then run through a simple set of if statements to demonstrate a line robots reactions. modified 19th July 2019 by Sebastian Karam - Flux Workshop */ int digitalLpin = 7; // define L signal pin int digitalCpin = 6; // define C signal pin int digitalRpin = 5; // define R signal pin int digitalL; // define variable to store value read from pin int digitalC; // define variable to store value read from pin int digitalR; // define variable to store value read from pin void setup() { pinMode(digitalLpin, INPUT); // set the L signal pin as an input pinMode(digitalCpin, INPUT); // set the C signal pin as an input pinMode(digitalRpin, INPUT); // set the R signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { digitalL = digitalRead(digitalLpin); // read the voltage level on the D7 digitalC = digitalRead(digitalCpin); // read the voltage level on the D6 digitalR = digitalRead(digitalRpin); // read the voltage level on the D5 Serial.println((String)"L: " + digitalL + " C: " + digitalC + " R: " + digitalR); // send the result to the serial monitor String reading = String(digitalL) + String(digitalC) + String(digitalR); // builds the result into a single string if(reading == "011"){ Serial.println("Turn right, turn right!"); // the line is being detected on the left } if(reading == "101"){ Serial.println("We have the line!"); // the line is being detected in the center } if(reading == "110"){ Serial.println("Turn left, turn left!"); // the line is being detected on the right } delay(500); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is moved from looking at white paper across a black line and back. The response changes as each sensor passes across the line, triggering the 'if' statement response. You will notice when one of the states are not met, no message other then the output values are returned. These will need to be considered unknown responses to a robot and may call back to its last known trigger.
This example will demonstrate the use of an Arduino UNO in selecting the module from the i2c bus and reading the sensor output. Once stored, it will check and pass them to the serial monitor. This will use the BH1750 sensor library created by Claws to interface with the chipset.
Wire the two boards together as can be seen in the image below, taking care to match the pin numbers.
The code consists of includes, initialisations, a simple setup and loop. First the Wire.h standard library and BH1750 sensor library are linked to the code. These are then used to initialise a sensor object and event object that will interact with the module. Next the setup launches the serial monitor, which provides a simple method to debug our output. In the loop we first poll the sensor for fresh data. With the data in hand we can perform further functions on it. In this case simply displaying it on the serial monitor.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the GY-30 (BH1750) sensor library and the module - BDAA100002 The program uses Claws BH1750 library to interact and monitor the output from the module through an I2C communication channel. On reading from the module it to outputs the result to the serial monitor. modified 12th July 2019 by Sebastian Karam - Flux Workshop The Adafruit Unified Sensor Driver library created by Claws https://github.com/claws/BH1750 */ #include// include the standard Wire library #include // include the BH1750 library BH1750 GY30; // instantiate a sensor event object void setup(){ Serial.begin(9600); // launch the serial monitor Wire.begin(); // Initialize the I2C bus for use by the BH1750 library GY30.begin(); // Initialize the sensor object Serial.println("Flux Workshop Example"); } void loop() { float lux = GY30.readLightLevel(); // read the light level from the sensor and store it in a variable Serial.println((String)"Light: " + lux + " lx"); // print the data to the serial monitor delay(1000); // Pause for a second before repeating the sensor poll }
With the board loaded with the program and all the connections made the serial monitor will begin to show the data output by the module. In the example, I start with the module covered with my hand, then remove it. Following that I turn the sensor to the window and back, before covering it once again.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of light levels that the sensor responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a variable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then launches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the UVM-30A ultraviolet sensor module - BDAA100001 The program monitors a connected analog pin and outputs the value to the serial monitor. modified 5th July 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"UV level: " + analogA); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in daylight before it is covered. Note the values are low in the example below, thanks to the lovely British summer we had no sun for the test. When in full sun/under a UV lamp the results should read around 30.
This example will demonstrate the use of an Arduino UNO in requesting and interpretting data from a DS18b20 sensor. Once connected and the program loaded, the serial monitor will display a live temperature readout. This will use the OneWire library created by Paul Stoffregen and the DallasTemperature library created by Miles Burton.
Wire the components together as can be seen in the image below, taking care to match the pin numbers.
The code consists of the an include, definition, launch, setup and loop. First the OneWire library and the DallasTemperature library are linked to the code. The sensor pin is defined followed by the OneWire library and DallasTemperature library instances established. The setup launches the serial connection and sensor connection. The loop contains the control program that will run continuously after the setup. It begins by requesting the information from the sensor instance. It then prints the value to the serial monitor.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the DallasTemperature library and DS18b20 Temperature probe - BIAA100074 The program uses the OneWire and DallasTemperature libraries to request and output temperatures from a DS18b20 sensor to the serial monitor. modified 28 June 2019 by Sebastian Karam - Flux Workshop The OneWire library created by Paul Stoffregen https://github.com/PaulStoffregen/OneWire The DallasTemperature library created by Miles Burton https://github.com/milesburton/Arduino-Temperature-Control-Library */#include <OneWire.h>
#include <DallasTemperature.h> // Define the pin that the sensor pin #define ONE_WIRE_BUS 2 // Establish a oneWire instance OneWire oneWire(ONE_WIRE_BUS); // Establish Dallas Temperature instance DallasTemperature sensors(&oneWire); void setup(void) { Serial.begin(9600); // Open a serial communication line sensors.begin(); // Start up the DallasTemperature library } void loop(void){ sensors.requestTemperatures(); // Request temperatures from the sensors instance Serial.print("Temperature (Celsius): "); // Print to the serial monitor Serial.print(sensors.getTempCByIndex(0)); // Print the temperature from the library to serial monitor Serial.print("\n"); // Print to the serial monitor delay(1000); // Pause before restarting the loop }
With the board is loaded with the program and all the connections made the module will begin to output a temperature in celcius. The animation below shows a brief loop of the sensor being placed in cold cup of water then into a hot cup of water and then back to the cold.
This example will demonstrate the use of an Arduino UNO in controlling the module. Once connected and the program loaded, lights will perform a pedestrian crossing sequence and provide feedback to the serial monitor.
Wire the two boards together as can be seen in the image below, taking care to match the pin numbers.
The code consists of the definitions, a setup and a single loop. Initially the pin numbers and delay lengths are defined. Following this the setup defines the pins as outputs, sets them to a starting value and then launches the serial monitor. The loop contains the control program that will run continuously after the setup. The loop monitors the serial input for the letter 'P'. Once it has been entered into the monitor, the sequence begins. First the green light is extinguished and the amber light lit. A loop cycles it through a number of times as defined by the earlier declared delay variable, each cycle passes through a pause. On completion the amber turns to red and it pauses once more in the same fashion. Following which the flashing amber state is reached. The flashing is controlled by doubling the amber delay, halving the pause and toggling the amber pin on each loop through. Once this has been completed the sequence finalises, the green is lit and the initial state restored.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the 3 Traffic Light LED module - BBAA100043 The program simulates a simple pedestrian crossing. modified 21 June 2019 by Sebastian Karam - Flux Workshop */ int redLEDpin = 13; // pin number for the red LED int amberLEDpin = 12; // pin number for the amber LED int greenLEDpin = 11; // pin number for the green LED int amberDelay = 5; // pause in seconds to maintain the amber light int redDelay = 10; // pause in seconds to maintain the red light void setup() { pinMode(redLEDpin, OUTPUT); // set the R signal pin as an output pinMode(amberLEDpin, OUTPUT); // set the Y signal pin as an output pinMode(greenLEDpin, OUTPUT); // set the G signal pin as an output digitalWrite(redLEDpin,LOW); // set the red LED to off by default digitalWrite(amberLEDpin,LOW); // set the amber LED to off by default digitalWrite(greenLEDpin,HIGH); // set the green LED to on by default Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Traffic Light Example"); Serial.println("Enter P to Cross"); } void loop() { // send data only when you receive data: if (Serial.available() > 0) { // check if data is available on the serial input char input = Serial.read(); // store the serial data in a variable if (input == 'P'){ // check if the incoming data is the letter 'P' Serial.println("--- BUTTON HAS BEEN PRESSED ---"); Serial.println("--- GOING TO AMBER ---"); for (int count = 0; count <= amberDelay; count++){ // Loop through the amber sequence digitalWrite(amberLEDpin,HIGH); // set the amber LED to on digitalWrite(greenLEDpin,LOW); // set the green LED to off delay(1000); } Serial.println("--- GOING TO RED ---"); for (int count = 0; count <= redDelay; count++){ // Loop through the amber sequence digitalWrite(amberLEDpin,LOW); // set the amber LED to off digitalWrite(redLEDpin,HIGH); // set the red LED to on delay(1000); } Serial.println("--- GOING TO FLASHING AMBER ---"); for (int count = 0; count <= amberDelay*2; count++){ // Loop through the flashing amber sequence digitalWrite(amberLEDpin,!digitalRead(amberLEDpin)); // toggle the amber LED digitalWrite(redLEDpin,LOW); // set the red LED to off delay(500); // this is a shortened delay for it to flash faster } Serial.println("--- GOING TO BACK TO GREEN ---"); digitalWrite(amberLEDpin,LOW); // set the amber LED to off digitalWrite(greenLEDpin,HIGH); // set the green LED to on delay(1000); Serial.println("Enter P to Cross"); // resend the instruction } } }
With the board loaded with the program and all the connections made the serial monitor will begin and await the input of the letter 'P'. The sequence will then begin. The output should be as seen below. Please note the camera has a hard time dealing with bright LEDs.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of light levels that a IR detector responds to as it moves from a white reflective surface to a black absorbent one.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes White/Black Line Sensor Module. The program monitors a connected analog pin and outputs the value to the serial monitor. modified 14th June 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Line Detection: " + analogA); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is moved from looking at white paper to a large black spot and back. The value gets higher as less of the IR light is reflected back onto the receiver.
This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of light levels that an LDR responds to.
Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.
The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the Keyes LDR Sensor Module. The program monitors a connected analog pin and outputs the value to the serial monitor. modified 7th June 2019 by Sebastian Karam - Flux Workshop */ int analogApin = 0; // define OUT signal pin int analogA; // define variable to store value read from pin void setup() { pinMode(analogApin, INPUT); // set the OUT signal pin as an input Serial.begin(9600); // launch the serial monitor Serial.println("Flux Workshop Example"); } void loop() { analogA = analogRead(analogApin); // read the voltage level on the A0 Serial.println((String)"Light level: " + analogA); // send the result to the serial monitor delay(200); // pause for a moment before repeating }
With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is in bright sunlight before it is covered by a cup.
This example will demonstrate the use of an Arduino UNO reading byte data from the sensor. Once connected and the program loaded, it will read the temperature and humidity, every second and a half (the sensor has a refreshes it's reading every second). This will use the SimpleDHT library library created by Winlin.
Wire the two boards together as can be seen in the image below, taking care to match the pin numbers.
The code consists of an include, definitions, initilisation, setup and loop. First the SimpleDHT library is linked to the code. This is followed by the initilisation of the sensor object used by the library and the pin it is connected to. The setup initilises the serial connection. The loop requests the temperature and humidity from the library, storing it in the byte variables declared. The values are then output to the serial connection, pausing for a moment and repeating.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the SimpleDHT library and Keyes DHT11 Temperature and Humiditiy Module - BDAA100058 The program uses the SimpleDHT library to interface with the module and return a temperature and humidity to the serial monitor. Then repeat the request. modified 31 May 2019 by Sebastian Karam - Flux Workshop The SimpleDHT library created by Winlin https://github.com/winlinvip/SimpleDHT */ #include// include the SimpleDHT library int sensorPin = 2; // define the pin the sensor is connected to SimpleDHT11 dht11Sensor(sensorPin); // create the sensor object void setup() { Serial.begin(9600); // initialise the serial connection } void loop() { byte temperature = 0; // define a variable to store the temperature byte humidity = 0; // define a variable to store the humidity dht11Sensor.read(&temperature, &humidity, NULL); // read the values from the DHT11 Serial.println("-------------------"); Serial.println((String)"Temperature: " + (int)temperature + "degC"); // send the result to the serial monitor Serial.println((String)"Humidity: " + (int)humidity + "%"); // send the result to the serial monitor delay(1500); // pause for a moment before repeating }
With the board loaded with the program and all the connections made, start the serial monitor. An initial value for the temperature and humidity will appear. The output should be as seen below (in this instance, held free, then moist air blown momentarily across it).
This example will demonstrate the use of an Arduino UNO in controlling the module. Once connected and the program loaded, the display will cycle through all the LEDs.
Wire the two boards together as can be seen in the image below, taking care to match the pin numbers.
The code consists of the a setup and single loop. The setup defines the pins to be used in the control of the module. The loop contains the control program that will run continuously after the setup. The loop cycles through each of the LEDs toggling it from it's current state to the next.
Load the code below into the Arduino IDE and upload it to your board.
/* A simple program designed to setup and demonstrate the 6 status LED module - BBAA100008 The program selects LEDs in order and lights it. modified 24 May 2019 by Sebastian Karam - Flux Workshop */ // these constants won't change: const int pinCount = 6; // the number of LEDs in the display int LEDpin[] = { 8, 9, 10, 11, 12, 13 }; // an array of pin numbers to which LEDS is attached void setup() { for (int thisLED = 0; thisLED < pinCount; thisLED++) { // loop over the LED pin array and set them all to outputs pinMode(LEDpin[thisLED], OUTPUT); digitalWrite(LEDpin[thisLED],LOW); } } void loop() { // the loop function runs over and over for (int thisLed = 0; thisLed < pinCount; thisLed++) { digitalWrite(LEDpin[thisLed],!digitalRead(LEDpin[thisLed])); // toggles the LED delay(100); } }
With the board loaded with the program and all the connections made the display will begin to cycle through all the LEDs in the module. The output should be as seen below. Please note the camera has a hard time dealing with bright LEDs.