We’ve arrived at part 3 of our series on how to make a Stevenson screen with Arduino. We’ve become quite comfortable using Arduino. Last time, we learned how to use 7-segment LED to display values. Today, we will implement the humidity sensor, one of the primary function of the Stevenson screen. We will also simplify the cabling of Arduino to make the Stevenson screen easier to use.
Expected time to complete: 60 minutes
Parts needed:
Before we begin our work, let us review once again the specifications of the Stevenson screen that we are trying to build.
The features we’d like to implement for our Stevenson screen (Specification sheet):
According to the plan, we are working towards implementing the above features in the Stevenson screen. The humidity sensor is a basic feature that hardly needs to be mentioned explicitly on such a list. For items 2 and 3, we can take care of them this time with an AC adapter or batteries.
A staple among humidity sensors, the TDK CHS-UGR
Let’s start by learning how to use the humidity sensor. Since the humidity sensor we have selected is very easy to use, not much knowledge is necessary.
We will be using the humidity sensor CHS-UGR, which display 100% RH with a DC.1V output. To put it simply, if we set the humidity sensor as an analog input, 0V = if the analog input on the Arduino is 0, the humidity is 0%, and 1.0V = if the analog input on the Arduino is 205, the humidity is 100%. We will build a circuit based on this specification.
The humidity sensor is larger than the parts we have been using until now
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
int sensorPin = A0; int sensorValue = 0; void setup() { Serial.begin(9600); } void loop() { sensorValue = analogRead(sensorPin); Serial.print("input value:"); Serial.println(toHumidity(sensorValue)/); delay(1000); } //Convert the analog input value to humidity float toHumidity(int analog_val){ float v = 5; // Standard voltage value ( V ) float tempC = (analog_val / (1024/v)) * 100; if(tempC &> 100){ tempC = 100; } return tempC } |
You can see that both the breadboard circuit and the program are simple.
In the above program, the analog input is basically read in the same way as the temperature sensor. The value is converted based on the specifications of the humidity sensor, allowing us to measure the humidity data. The humidity sensor will input analog values from 0–205 (all higher values are set to 100%), so we create a function that applies to the part written in red.
If you run Arduino, the serial monitor should show something similar to what is displayed below. By placing your hand close to the sensor or breathing on it, you should be able to verify that it detects the humidity and the values will change accordingly.
Now that we know how to use both the temperature and humidity sensors, we will place both sensors on the breadboard and get both values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
int temperaturePin = A0; // select the input pin for the potentiometer int humidityPin = A1; // select the input pin for the potentiometer int temperatureValue = 0; // variable to store the value coming from the sensor int humidityValue = 1; // variable to store the value coming from the sensor void setup() { Serial.begin(9600); } void loop() { temperatureValue = analogRead(temperaturePin); humidityValue = analogRead(humidityPin); Serial.print("temperature:"); Serial.print(toTemperature(temperatureValue)); Serial.print("/ humidity:"); Serial.println(toHumidity(humidityValue)); delay(1000); } //Convert analog input to celsius float toTemperature(int analog_val){ float v = 5; // Standard voltage value ( V ) float tempC = ((v * analog_val) / 1024) * 100; return tempC; } //Convert analog input to humidity float toHumidity(int analog_val){ float v = 5; // Standard voltage value( V ) float tempC = (analog_val / (1024/v)) * 100; if(tempC &> 100){ tempC = 100; } return tempC; } |
We are able to get the data from the temperature sensor with analog pin #0, and from the humidity sensor with pin #1.
Now, let’s start using the 7-seg LED from last time and display the temperature and humidity in sequence.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
// // Program to display temperature/humidity on 7-segment LED // int _cnt = 0; // int _number = 0; // int temperaturePin = A0; // select the input pin for the potentiometer int humidityPin = A1; // select the input pin for the potentiometer int temperatureValue = 0; // variable to store the value coming from the sensor int humidityValue = 1; // variable to store the value coming from the sensor boolean _switchFlg = false; //Flag for switching between temperature/humidity display boolean _flg = false; void setup(){ Serial.begin(9600); //Set pins 2-8 to digital output for (int i=2; i&<=8; i++){ pinMode(i,OUTPUT); } pinMode(13,OUTPUT); pinMode(11,OUTPUT); } // Define LED layout boolean Num_Array[10][7]={ {1,1,1,1,1,1,0}, //0 {0,1,1,0,0,0,0}, //1 {1,1,0,1,1,0,1}, //2 {1,1,1,1,0,0,1}, //3 {0,1,1,0,0,1,1}, //4 {1,0,1,1,0,1,1}, //5 {1,0,1,1,1,1,1}, //6 {1,1,1,0,0,1,0}, //7 {1,1,1,1,1,1,1}, //8 {1,1,1,1,0,1,1} //9 }; // Define LED display function void NumPrint(int Number){ for (int w=0; w&<=7; w++){ digitalWrite(w+2,-Num_Array[Number][w]); } } // Parse 2 digits into individual digits int NumParse(int Number,int s){ if(s == 1){ return Number % 10; } else if(s == 2){ return Number / 10; } return 0; } void loop(){ // Obtain temperature/humidity and set variable to converted value if(_switchFlg){ _number = toTemperature(analogRead(temperaturePin)) } else{ _number = toHumidity(analogRead(humidityPin)) } if(_flg){ digitalWrite(11,LOW); digitalWrite(13,HIGH); _flg = false; NumPrint(NumParse(_number,1)); } else{ digitalWrite(11,HIGH); digitalWrite(13,LOW); _flg = true; NumPrint(NumParse(_number,2)); } if(_cnt &>= 100){ _cnt = 0; if(_switchFlg){ _switchFlg = false; } else{ _switchFlg = true; } } _cnt++; delay(10); } //Convert analog input value to Celsius float toTemperature(int analog_val){ float v = 5; // Standard voltage value ( V ) float tempC = ((v * analog_val) / 1024) * 100; return tempC; } //Convert analog input value to humidity float toHumidity(int analog_val){ float v = 5; // Standard voltage value ( V ) float tempC = (analog_val / (1024/v)) * 100; if(tempC &> 100){ tempC = 100; } return tempC; } |
In this program, we are basically sending analog values to the 7-seg LED display program we created previously. But since we also want to display both temperature and humidity in sequence, we use _switchFlg as a flag which switches between true/false in a set interval, in order to alternate _number between temperature and humidity. This time, we increment _cnt at the end of the loop function every delay(10) = 0.01 seconds, and when _cnt reaches 100, we reset _cnt to 0 and switch the value of _switchFlg, therefore the alternation occurs every 0.01sec×100=1 second.
We’re finally at the point where the functionality of the Stevenson screen is complete. Let’s operate Arduino with a different power source. Until now, we have been using Arduino by connecting it to a PC with a USB cable. But as we discussed, the programs are already stored on Arduino, so it is operational as long as we can secure a power source.
How much power do we actually need for Arduino? On the specification for Arduino UNO that we have been using, the minimum operational voltage is 5V, and the standard voltage is 7–12V. Today, we’ll attempt to use an AC adapter and a 9V battery as power sources for Arduino.
To use Arduino with an AC adapter, simply plug in the adapter to the adapter port on Arduino.
To use Arduino with a 9V battery, you can connect it just like the AC adapter as long as the battery box is compatible with the Arduino port. However, if it is wired, you can power it by connecting the + side to Arduino’s Vin port and connecting the – side to GND.
By comparing it to a cell battery, we can really see how small Arduino is.
Now, let us review the specifications:
We have implemented most of the features we established at the beginning. There happened to be a stand clip for smartphones by my side, so I’ve made a rudimentary setup.
Wow, the circuit board looks cool here when it’s shown like that.
But it looks like the wiring can come off easily, and it’s connected by wire to Arduino base… It will certainly fall apart with a little bump! (Laughs)
This is definitely far from being complete. Next time, I’d like to build on what’s been done so far, and complete our Stevenson screen, and include an external case!