Good afternoon,
I struggle a problem with my Arduino uno and wifi shield (also from Arduino).
I use a quite simple code which is shown below.
It just measures the temperature (and changes an RGB led colour according to that) AND connects to an WPA2 wifi network.
I do get the message "connected" so all seems to work pretty well...however - how do I connect to it to get the printing via wifi which is shown in Arduino's 'Serial Monitor'.
Does it work by typing the shield's IP into the internetexplorer, when also connected to the same WPA2 networl,.....and how do I get the shield's IP address?
Thanks a lot for any help,
Peter
#include <WiFi.h>
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int redPin = 9; // R petal on RGB LED module connected to digital pin 11
int greenPin = 11; // G petal on RGB LED module connected to digital pin 9
int bluePin = 10; // B petal on RGB LED module connected to digital pin 10
char ssid[] = "XXXXXX"; // your network SSID (name)
char pass[] = "XXXXXX"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
// attempt to connect using WPA2 encryption:
Serial.println("Attempting to connect to WPA network...");
status = WiFi.begin(ssid, pass);
// if you're not connected, stop here:
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// if you are connected, print out info about the connection:
else {
Serial.println("Connected to network");
}
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
}
void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function
{
analogWrite(redPin, 255-red);
analogWrite(greenPin, 255-green);
analogWrite(bluePin, 255-blue);
}
void loop() // run over and over again
{
int reading = analogRead(sensorPin); //getting the voltage reading from the temperature sensor
float voltage = reading * 5.0; // converting that reading to voltage, for 3.3v arduino use 3.3
voltage /= 1024.0;
Serial.println("_____________________________"); // print out the voltage, println erzeugt einen folgenden Zeilenumbruch
Serial.print("Gemessene Spannung: "); Serial.print(voltage); Serial.println(" Volt");
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset; to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC);Serial.println(" Grad Celsius"); // now print out the temperature
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; // now convert to Fahrenheight
Serial.print(temperatureF); Serial.println(" Grad Fahrenheit");
if (temperatureC <= 0)
{
Serial.println("Temperature: unter 0");
Serial.println("Farbe: Weiss");
color(255,255,255);
}
else if ((temperatureC >0) && (temperatureC <= 5))
{
Serial.println("Temperature: 0 - 5");
Serial.println("Farbe: Tuerkis");
color(127,255,212);
}
else if ((temperatureC > 5) && (temperatureC <= 10))
{
Serial.println("Temperature: 5 - 10");
Serial.println("Farbe: Dunkelblau");
color(0,0,255);
}
else if ((temperatureC >10) && (temperatureC < 15))
{
Serial.println("Temperature: 10 - 15");
Serial.println("Farbe: Gruen");
color(0,100,0);
}
else if ((temperatureC > 15) && (temperatureC < 20))
{
Serial.println("Temperature: 15 - 20");
Serial.println("Farbe: Hellgruen");
color(124,252,15);
}
else if ((temperatureC > 20) && (temperatureC < 25))
{
Serial.println("Temperature: 20 - 25");
Serial.println("Farbe: Gelb");
color(255,255,0);
}
else if ((temperatureC > 25) && (temperatureC < 30))
{
Serial.println("Temperature: 25 - 30");
Serial.println("Farbe: Orange");
color(255,69,0);
}
else
{
Serial.println("Temperature: ueber 30");
Serial.println("Farbe: Rot");
color(255,0,0);
}
delay(5000); //erneute Messung in 5 Sekunden
}