Trouble with setup

Hi, I recently bought the arduino begginer kit and I finished all the projects. I was thinking to combine some of them to make my own projects. I attatched a jpeg file of the two projects that I combined. The only difference is I took out the LED, pushbutton and the resistors.

The problem I am having is that whenever the condition is met (Temp. > 30) then I hear fast clicking sounds. I assume this is the relay and after a while the serial monitor stops and the IDE wont let me upload any code again until I hit the reset button. The code is as follows:

float sinVal;
int toneVal;
unsigned tepTimer;
int relayPin = 3;

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

void loop() {
  int val;
  double data;
  val = analogRead(0);
  data = (double) val * (5 / 10.24);

  if (data > 30) {                  // if temperature is above 30 degrees celsius
   digitalWrite(relayPin, HIGH);
    for (int x = 0; x < 180; x++) {
      sinVal = (sin(x * (3.142 / 180)));
      toneVal = 2000 + (int(sinVal * 1000));
  } else {
    digitalWrite(relayPin, LOW);
  if (millis() - tepTimer > 500) {    //to output data every 500 milliseconds
    tepTimer = millis();
    Serial.print("temperature: ");

Also, I did not connect the components in such a way that they overlap, each component still functions in their own rows as in the individual projects.

This for loop does a whole lot of calculations and throws the results in the bit bucket.

   for (int x = 0; x < 180; x++) {
      sinVal = (sin(x * (3.142 / 180)));
      toneVal = 2000 + (int(sinVal * 1000));

Images from Original Post so we don’t have to download it. See Image Guide




Can you make a hand-drawn schematic on a piece of paper and post a photo of that. I can't make sense of those images because I know nothing about the hardware you are using.


You have no flyback diode on the relay.