To conclude our final project for the computer science class, we produced an Internet of things device which is a development of the Internet in which everyday objects have network connectivity, allowing them to send and receive data. For our class, we created an internet of things device which allowed us to measure temperature in which was sent to a web server for us to access through an IP address. Below are the steps on how to produce a internet things of device which allows you to send and receive data regarding temperature.
Obtain the following items: Internet of Things”(IoT) kit,Arduino board, 10 Thermistor temperature sensor, Arduino Ethernet Shield, cable & power supply.
Assemble the breadboard, take the Arduino Uno board and fix it onto the breadboard. The arduino uno should be parallel to your breadboard. *Note: Arduino boards read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online.
Next, take the ethernet shield, plug all headers into the shield. Make sure you insert them in the correct direction. The male pins of the header should enter the top side of the shield and extend out the bottom. *Note: The Arduino Ethernet Shield 2 connects your Arduino board to the internet. Important for creating a web server to see temperature values.
With these pins soldered, plug the shield into your Arduino. Make sure your Arduino’s not powered while you do this alignment check.
All of the pins should be well-aligned and the shield should slide right into the Arduino. Take care not to bend any pins while inserting, and make sure they all go into the headers.
Take a 2 red wires, 1 blue wire, 2 black wires, 1 temperature probe, 1 resistor and a Arduino cable.
Place one end of the resistor in the horizontal penultimate hole under column 21, and the second end in the 2nd hole in column 16. *Note: The (thermal) resistor is a resistor that changes its resistance with temperature. They are made so that the resistance changes drastically with temperature so that it can be 100 ohms or more of change per degree
8) Take a black wire and search for the + and - ports which are at the top/bottom of the board. In either of the two ends, insert one end of the black wire into the positive hole and the other into the positive hole horizontally across from the first end of the wire.
Next take the red wire and do the same method as mentioned above, only plugging the wire into the negative port.
Take the 2nd black wire and plug one end of the wire into the first hole, horizontal to column 21. Insert the other end of the wire in a GND hole, on the Arduino shield.
Take a blue wire and plug one end of the wire into the A0 port and the other end in first hole next to column 16.
Obtain the 2nd red wire and plug one end into the first hold in column 15 and the other end into the GND port(next to the black wire).
Next, take the temperature probe and unwind the two ends of wire at the bottom of the probe, so that there are two ‘branches’.
Place one end of the temperature probe in the last hole in column 16(parallel with the blue wire) and the other end in the last hole in column 15.
This is how all your wiring should look like:
Double check your wiring to make sure all of the wires are inserted deep inside the holes so that the board is able to carry out its task.
-
Open Arduino and copy the following code into the document: #include <Ethernet2.h> // Used for Ethernet #define THERMISTORPIN A0 // which analog pin to connect #define THERMISTORNOMINAL 10000 // resistance at 25 degrees C to calibrate thermistor #define TEMPERATURENOMINAL 25 // temp. for nominal resistance (almost always 25 C) #define NUMSAMPLES 5 // how many samples to take and average; smooth out reading #define BCOEFFICIENT 3950 // The beta coefficient of the thermistor (usually 3000-4000) #define SERIESRESISTOR 10000 // the value of the 'other' resistor // **** ETHERNET SETTINGS **** byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0xA0, 0xEE }; // MAC address of your Arduino (must be unique) IPAddress dnServer(10,1,2,2);// the dns server ip IPAddress gateway(10,3,0,1);// the router's gateway address: IPAddress subnet(255, 255, 192, 0);//the subnet IPAddress ip(10,3,15,1); //the IP address of your arduino EthernetClient client; char server[] = "10.3.15.14"; // IP Adress (or name) of server to dump data to // **** OTHER VARIABLES **** int interval = 60000; // Wait between dumps int samples[NUMSAMPLES]; //How many temp readings go into the average reading char sensorName[] = "Pfrape_Arduino"; //identifies this sensor in the database // **** START UP SCRIPT - SETS UP ETHERNET AND OTEHR THINGS **** void setup() { Serial.begin(9600); Ethernet.begin(mac, ip, dnServer, gateway, subnet); Serial.println("ISKL - Temperature Drone - v2.0"); Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"); Serial.print("IP Address : "); Serial.println(Ethernet.localIP()); Serial.print("Subnet Mask : "); Serial.println(Ethernet.subnetMask()); Serial.print("Default Gateway IP: "); Serial.println(Ethernet.gatewayIP()); Serial.print("DNS Server IP : "); Serial.println(Ethernet.dnsServerIP()); } // **** RUNS AFTER STARTUP, ALL THE TIME ***** void loop() { // if you get a connection, report back via serial: if (client.connect(server, 80)) { Serial.println("-> Connected"); float tempC = getTemperature(); Serial.print("Temp: "); Serial.println(tempC); // Make a HTTP request: client.print( "GET /add_data.php?"); client.print("serial="); client.print(sensorName); client.print("&"); client.print("temperature="); client.print( tempC ); client.println( " HTTP/1.1"); client.print( "Host: " ); client.println(server); client.println( "Connection: close" ); client.println(); client.println(); client.stop(); } else { // you didn't get a connection to the server: Serial.println("--> connection failed/n"); } delay(interval); } // **** FUNCTION TO GET 'AVERAGE' TEMPERATURE FROM THE SENSOR **** float getTemperature() { uint8_t i; float average; for (i=0; i< NUMSAMPLES; i++) {// take N samples in a row, with a slight delay samples[i] = analogRead(THERMISTORPIN); delay(1); } average = 0; for (i=0; i< NUMSAMPLES; i++) {// average all the samples out average += samples[i]; } average /= NUMSAMPLES; // convert the average value to resistance average = 1023 / average - 1; average = SERIESRESISTOR / average; //Serial.print("Thermistor resistance "); //Serial.println(average); float steinhart; steinhart = average / THERMISTORNOMINAL; // (R/Ro) steinhart = log(steinhart); // ln(R/Ro) steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro) steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; // convert to C //send value back to the caller return steinhart;
18) Change your MAC Address, IP Address, Subnet, Gateway and DNS to your designated numbers in the code above. In my case, my values are as listed below. Also, set the resistor value to '10k'. MAC Address: 90:a2:da:10:a1:0e
IP Address: 10.3.15.7
Subnet: 255.255.192.0
Gateway: 10.3.0.1 DNS: 10.1.2.2
19) Next we need to use the ethernet2 library for the Arduino Shield 2. Go to Sketch > Include Libraries > Manage Libraries and add the ethernet2 library as in the attached screenshot. Then you need to change your include to: #include <Ethernet2.h>
20) Plug in your Arduino cable to the board and your computer to transfer the code. Once connected, go to Tools> Port and select “Arduino Uno”.
21) Click the verify(checkmark icon) button in the document to make sure the coding is correctly formatted. Once it has been compiled, hit the upload(arrow icon) button to transfer the code to the board.
22) Connect your Arduino Shield to the switch(ethernet port) near the wall like this: Note *
If your arduino is placed in a different room, use a power supply to power your Arduino. Search for an ethernet port in the room, and then connect the Arduino into it. A power supply is is an internal hardware component that supplies components in a computer with power.
22) Open the Arduino serial monitor and make sure the thermistor is measuring the correct values
23) Next, browse to your Arduino’s IP address to see if it will serve up a webpage to you with the temperature on it. If it works it will show temperature values such as the following:
*24(optional) Decorate your arduino to make it look presentable. Be creative! This is how I did mine!