Today I will discuss about use the digital temperature module with the use of 18B20 (Programmable 1-Wire digital Thermometer) so we can measure the temperature in our environment. The following are the things that we need. Arduino board, the digital temperature 18B20 module, jumper wires and breadboard. Information about digital temperture 18B20 module This module reports degrees in Celsius from -55 to 125 celsius degrees, with +- 0.5 accuracy/precision. It has 3 pins, namely: VCC, D0 and GND. it can be used as thermometer. This sensor has 1-wire interface, in which only one pin will be required to communicate with the Arduino to read the temperature of one or more sensors. Each 18B20 has a unique 64 bit serial code, which allows multiple sensors to function on the same 1-Wire bus (data line). The 18B20 temperature sensor can derive power directly from the data line ("parasite power"), in which you may not need an external power source. In our module, you just connect the VCC pin to the 5V of Arduino. This temperature sensor can be used to temperature monitoring systems in your home, buildings, machine, equipment and other process control systems. Materials: Arduino board (Uno or any compatible) Breadboard DS18B20 temp sensor module (if you have no module, and you have just a sensor, you need to get 4.7k ohms to be connected between signal pin and 5V pin) The OneWire library is typically used for a one-wire components like digital temperature sensor. The Dallas library is used to simplify and to shorter the code for processing the output of the temperature sensor. Make sure all these libraries are included in your Arduino IDE to compile it successfully.
We discussed the passive buzzer module from the previous article. You may wonder what's the difference between these two buzzers. The passive buzzer requires an AC signal (oscillating signal) to make a sound, while the passive signal don't need the oscillating signal to produce a sound. The active buzzer can produce a tone automatically by simply applying a DC voltage. An active buzzer generates tone using the internal oscillator. To check if you have a passive or active buzzer, apply a voltage source to the buzzer. If it buzzes, it means you have an active buzzer. For more control in the programming to produce tone or sound, better to use active buzzer. The active buzzer does not need to use hardware timer or additional code to make sound. In fact, you don't need the Arduino to produce sound with the use of active buzzer. Just apply the voltage and it will produce a buzz sound. Check the code below for active buzzer code example //Simple code for active buzzer module const int buzzerPin = 5; void setup() { pinMode(buzzerPin, OUTPUT); } void loop() { // pulse the buzzer on for 150ms digitalWrite(BuzzerPin, HIGH); delay(100); digitalWrite(buzzerPin, LOW); delay(1500); } In the sample code, the buzzer produces a buzz sound for 150 milliseconds and then turned off for 1.5 seconds. We can use an analogWrite() to produce different tones. Pin 9, 10 and 11 in Arduino can be used to write a PWM values using the analogWrite() function. We are going to use pin 9 to our code. See code below for an example using the analogWrite(). Code Editor
In the code above, it produces a simple sound with tune.
The analog inputs is used to measure the joystick position. The analog input values can be range between 0 and 1023. Keep in mind that the input values may vary. I suggest you test the joystick position so you could get an accurate result. See the figure for the common output orientation of the joystick. Notice on the joystick orientation that there's no negative values. the value x=512 and y=512 means that the position of the joystick handle is in the middle or the user did no touch it. If value of x= 512 and y= 1023, the joystick handle is pushed-up. If the joystick values that you received do not match on the diagram, you may calibrate it or you may experiment and map all the positions with the right values. See the code below for joystick controller module Setup the joystick controller module.
Connect the X pin of joystick to A1 of Arduino, Y pin of joystick module to A2 of Arduino and switch pin of joystick to digital pin 3 of Arduino. Connect the GND pin of joystick to GND of Arduino and the VCC pin of joystick to 5V of Arduino. Once completed, upload the code to Arduino. If the code has been uploaded successfully, open the Serial Monitor of Arduino Editor and watch out the display as you move the joystick handle and pushing the joystick switch. You will see the values of x, y and the switch. I will discuss the photoresistor module today. Photoresistor is a sensor that can sense the amount of light intensity in your environment. This is typically used if you want to control any devices when the environment is dark or when it is light. Our photoresistor module has 3 pins. The left pin is the signal pin, where you connect it to the analog pin in Arduino for as input. The middle pin is the VCC pin (+5V) and the right pin is GND pin, where it should connect to the ground pin of arduino. The input value coming from the photoresistor produces voltage value, a maximum of +5V and a minimum of 0V. Once the arduino receives this voltage value, this will be converted into a number value, from 0 to 1023 value. if the input value is 1023, it means the voltage value produced by photoresistor is +5V. This will only happens when the photoresistor detects a very bright light in the environment, in which it causes the photoresistor reduces its resistance value. Let's try the photoresistor module functionality by uploading our code below. int sensorPin = A1; // set the input pin for the photoresistor
int led = 13; // set the pin for the LED int sensorValue = 0; // set the variable to store the value coming from the photoresistor sensor void setup() { pinMode(ledPin, OUTPUT); } void loop() { // read the value from the photoresistor sensor: sensorValue = analogRead(sensorPin); // turn on the LED digitalWrite(led, HIGH); // pause for milliseconds based on value from photoresistor: delay(sensorValue); // turn off the LED digitalWrite(led, LOW); // pause for milliseconds based on value from photoresistor delay(sensorValue); } Let's discuss the code inside the loop() function. The analogRead() returns a number between 0 and 1023 based on the voltage produced on Analog pin 1 of Arduino. The value returns will be used as the parameter value for the delay() function. The higher the number, the longer the pause of the system.
Code example- Simple sound for passive buzzer module
Upload this code to the arduino and you will hear sound from the passive buzzer. See below for screenshots of my passive buzzer demo. I'm using my Arduino Mega ADK for this demo. If you want to hear some familiar songs, there are many available samples in the internet. Try to get the code from the link and you will hear the fur elise song by Beethoven from the passive buzzer. Enjoy!
|