0

I am trying to build an emergency shutdown of a gas valve based on the output of a smoke detector.

It basically measures the voltage on the buzzer of the smoke detector, and if high enough, changes the direction of the motordriver, which is connected to an actuator (with automatic shutdown) that operates the gas valve.

A button is used to reset the alarm.

The actual setup is soldered on a prototype board, but below the layout as a breadboard.

breadboard layout

The nano is powered by a step down converter connected to the 5V pin, that in turn is powered by the 12V power supply that also drives the actuator. Its output is 5.13V according to my multimeter, and seems stable when I measure it.

The problem I have is that the system continuusly enters alarm state.

After some experimenting I have found out that when I short the analog pin to ground, I always read 0, but when I use a resistor, as in the breadboard layout, I get a couple of 0 readings, then a sort of peak, that goes back to 0, and that behaviour in a cycle of approximately 10 sec.

The cyclic pattern is consistent, the values differ depending on how I power the system (external of from the USB of my PC), and whether I connect the smoke detector or use the resistor.

Below the code (I left out the utility functions for brevity), and the output when I use the 100k resistor between A2 and ground, with the board powered by the USB connection.

Can anyone explain what is going on here?

void setup() {
  bool storedAlarm;

  initOutput(activeLedPin);
  initOutput(alarmLedPin);
  initOutput(gasValveIn1Pin);
  initOutput(gasValveIn2Pin);

  EEPROM.get(0,storedAlarm);
  alarm = false;

  Serial.begin(9600);
  Serial.print("start with Alarm "); 
  Serial.println( storedAlarm ? "ON" : "undetermined" );

  digitalWrite(activeLedPin, HIGH);
  blinkAlarmLed(500,333,3);

  if (storedAlarm) {
    switchAlarmOn();
  }
  // never switch off automatically
  // if the valve is open it will stay open
}
void loop() {
  int sensorValue = analogRead(sensorPin);
  bool reset = digitalRead(alarmResetPin);

  Serial.println(sensorValue);
  if ( sensorValue > 500 ) {
    switchAlarmOn();
    if (reset) {
      blinkAlarmLed(100,100,7); // show refusal
    }
  }
  else if ( reset ) switchAlarmOff();

  delay(800);
}

Output:

14:01:08.587 -> start with Alarm ON
14:01:11.061 -> alarm
14:01:11.367 -> 36
14:01:12.148 -> 35
14:01:12.963 -> 9
14:01:13.778 -> 0
14:01:14.559 -> 0
14:01:15.374 -> 0
14:01:16.155 -> 0
14:01:16.970 -> 0
14:01:17.784 -> 0
14:01:18.564 -> 0
14:01:19.380 -> 0
14:01:20.161 -> 0
14:01:20.974 -> 0
14:01:21.787 -> 17
14:01:22.568 -> 62
14:01:23.383 -> 65
14:01:24.162 -> 67
14:01:24.977 -> 54
14:01:25.791 -> 137
14:01:26.570 -> 104
14:01:27.385 -> 29
14:01:28.165 -> 17
14:01:28.980 -> 0
14:01:29.795 -> 0
14:01:30.575 -> 0
14:01:31.390 -> 0
14:01:32.171 -> 0
14:01:32.986 -> 0
14:01:33.801 -> 0
14:01:34.581 -> 0
14:01:35.397 -> 0
14:01:36.178 -> 0
14:01:36.993 -> 37
14:01:37.809 -> 64
14:01:38.589 -> 69
14:01:39.404 -> 64
14:01:40.184 -> 34
14:01:40.997 -> 136
14:01:41.811 -> 120
14:01:42.592 -> 46
14:01:43.406 -> 16
14:01:44.187 -> 8
14:01:45.003 -> 0
14:01:45.784 -> 0
14:01:46.600 -> 0
14:01:47.415 -> 0
14:01:48.196 -> 0
14:01:49.012 -> 0
14:01:49.793 -> 0
14:01:50.607 -> 0
14:01:51.422 -> 0
14:01:52.201 -> 0
14:01:53.016 -> 0
14:01:53.796 -> 0
14:01:54.611 -> 28
14:01:55.427 -> 53
14:01:56.208 -> 65
14:01:57.022 -> 72
14:01:57.803 -> 68
14:01:58.617 -> 73
14:01:59.432 -> 0
14:02:00.212 -> 140
14:02:01.027 -> 136
14:02:01.808 -> 101
14:02:02.622 -> 46
14:02:03.437 -> 22
14:02:04.218 -> 16
14:02:05.032 -> 8
14:02:05.812 -> 0
14:02:06.627 -> 0
14:02:07.409 -> 0
14:02:08.224 -> 0
14:02:09.038 -> 0
14:02:09.820 -> 0
14:02:10.633 -> 0
14:02:11.415 -> 0
14:02:12.231 -> 0
14:02:13.047 -> 0
14:02:13.828 -> 0
14:02:14.642 -> 0
14:02:15.422 -> 40
14:02:16.237 -> 73
14:02:17.050 -> 72
14:02:17.830 -> 65
14:02:18.644 -> 11
14:02:19.427 -> 131
14:02:20.240 -> 108
14:02:21.054 -> 61
14:02:21.834 -> 18
14:02:22.648 -> 14
14:02:23.428 -> 0
14:02:24.242 -> 0
14:02:25.058 -> 0
14:02:25.839 -> 0
14:02:26.654 -> 0
  • Please try to connect the resistor between A2 and Arduino ground as close as possible to GND pin. – AltAir Sep 29 at 17:31
  • Try it with a much lower value resistor. 100k is perhaps just too large – C.W.G Sep 29 at 17:57
  • With a 20k resistor directly between the Pin and ground the cyclic behaviour is still there, although the max value is then 20. – til Oct 1 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.