Step 2Program Arduino and set up ethernet shield
- Because the stoplight will serve as a server and needs to have a non-changing IP address, the IP address is hard coded in the sketch. You will want to change the line that says "byte ip[] = { 192, 168, 119, 177 }; " to match the IP address you want to assign the stoplight. Note that the quads that make up the IP address are separated by commas not dots. This is because the IP address is stored as an array of 4 bytes, each of which is one of the bytes of the IP address.
- Do the same thing for the "byte mac[] " line, substituting the MAC address of your ethernet shield. It should be printed on it somewhere.
- Change the "char secret[] " array to be whatever password you want to use.
- Change the number in the "EthernetServer server(####) " line to be whatever port you want the server to listen on. Normally this would port 80.
Ideally, you should have DNS set up for the stoplight server IP, so you can refer to it as something like http://stoplight.example.com but IP addresses work just as well.
After connecting you should see a simple web page that shows you the current status of each of the lights, complete with check boxes and a place to put your password to change each of them.
If you see the web page appear at all, you will know that your ethernet shield is working, and your arduino is now a web server, even if you can't see it affecting the outside world yet.
Watching the check boxes change without seeing the arduino do anything is pretty boring, so see the next step for an optional test rig you can build for instant (or at least sooner) gratification.
stoplight.zip22 KB| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|
















































