Step 3: Code

I wrote two programs, one to control the light sensor and LEDs and one to control the water sensor and speaker.  I based to code off the tutorials found here for the light sensor and speaker tutorials.

Light Sensor Code:
int LEDPin = 13;

int CDSPin = 0;

void setup(){
  pinMode(LEDPin, OUTPUT);

void loop(){
  int lightLevel;
  lightLevel = analogRead(CDSPin);
  if (lightLevel < 300)
    digitalWrite (LEDPin, HIGH);
  else if (lightLevel > 300)
  {digitalWrite (LEDPin, LOW);

Water Sensor Code:

int waterSensor = 2;

int ledPin = 13;

int speakerPin = 9;

int length = 15; // the number of notes
char notes[] = "gggefffd"; // a space represents a rest
int beats[] = { 
  1, 1, 1, 3, 1, 1, 1, 3, };
int tempo = 300;

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    digitalWrite(speakerPin, LOW);

void playNote(char note, int duration) {
  char names[] = { 
    'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 
    1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(speakerPin, OUTPUT);

void loop() {
  int sensorData;
  sensorData = analogRead(waterSensor);
  if (sensorData < 50){
    playTone('b', 100);
  else if (sensorData > 51){


can i do the same using PIC microcontroller<br>If so i need ur help
WOW, how is it that I haven't seen this until now? This is amazing, so functional and stylish! I've got an old trenchcoat that I should try this out on.<br><br>Do you know if this could work with umbrellas?
Ooo, another wearable etextile project. Private message<a href="https://www.instructables.com/member/Lynne+Bruning/"> Lynne Bruning</a> on your project so that you can show it in one of her Maker Faire etextile shows. She is always looking for cool stuff. I got to show off my light-up hoodie and gloves last year in the NYC Maker Faire.
Oh that would be sweet! It's probably going to a Maker Faire in Massachusetts and possibly the California Maker Faire as well, since I will be at both of them :)
Thanks Catlinsdad! You are the BEST!<br> <br> Danger - information for the Bay Area Showcase is listed on my <a href="http://bit.ly/dFWGse">website</a>.<br> Please please - bring your coat!&nbsp;<br>
If this project were to make it to the NYC Maker Faire, it might make some people less upset at rain that may fall during the event. &quot;Danger is my Middle Name&quot; could suit up and run out in the rain to put on a good show.<br>
Yes! I'd love to see a video of this. It sounds really cool!

About This Instructable




Bio: I'm just a lady who likes making stuff. I got my degree in engineering but also enjoy cooking, sewing, knitting, gardening and backpacking, among ... More »
More by Danger is my middle name:Rustic Cottage Cheese and Sausage Gluten Free Pancakes Pumpkin Spice Latte Cookies Wonder Woman 
Add instructable to: